package com.derek.omshopping.ui.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.derek.omshopping.R;
import com.derek.omshopping.bean.home.HomeMainTypeBean;
import com.derek.omshopping.config.UrlConfig;
import com.derek.omshopping.ui.home.view.DetailsPageActivty;

import java.util.List;

/**
 * Created by duyb on 2016-10-05.
 * Desc:首页轮播图
 */

public class HomeViewPageAdapter extends PagerAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<HomeMainTypeBean.SetListBean.ContentListBean> list;

    public HomeViewPageAdapter(Context context, List<HomeMainTypeBean.SetListBean.ContentListBean> list) {
        this.context = context;
        this.list = list;
       // Log.e("page-->",list.size()+"");
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        View view = inflater.inflate(R.layout.item_simpleview_viewpager, container, false);
        ImageView simple = (ImageView) view.findViewById(R.id.simpleView_simpleSlider_recycler);
        Glide.with(context).load(Uri.parse(UrlConfig.PRE_BASEURL+list.get(position).getContsPathNm()+list.get(position).getContsFileNm())).into(simple);
        container.addView(view);
        //点击跳转
        simple.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, DetailsPageActivty.class);
                String imgId=list.get(position).getConnectTgtAddr();
                intent.putExtra("imgId",imgId);
                Log.e("adapter--imgid",imgId);
                context.startActivity(intent);
            }

        });
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
